layui.define(["jquery"],function(exports){
    var $ = layui.jquery;
    // 设置jQuery Ajax全局的参数
    $.ajaxSetup({
        beforeSend: function(request) {
            var token = window.localStorage.getItem("token");
            request.setRequestHeader("Authorization", "bearer " + token);
        },
        complete: function(jqXHR){
            switch (jqXHR.status){
                case(500):
                    alert("服务器系统内部错误");
                    break;
                case(401):
                    alert("未登录");
                    break;
                case(403):
                    alert("无权限执行此操作");
                    break;
                case(404):
                    alert("404");
                    break;
                case(408):
                    alert("请求超时");
                    break;
                case(200):
                    var result = jqXHR.responseJSON;
                    var businessCode = result.code;
                    if(!result.success){
                        if(businessCode == 510100){
                            window.open('/page/login/login.html');
                        }
                    }
                    break;
                default:
                    alert("未知错误");
            }
        }
    });
    exports("jqCommon",{});
})